﻿
@{
    Layout = null;
}
<div ng-controller="AddressInfo">
    <div class="fsci_b">
        <div class="fsci_r">
            <span class="sci_l">收货人</span>
            <input type="text" placeholder="请输入收货人姓名" name="Consignee" id="Consignee" ng-model="Model.Consignee" class="sci_r">
        </div>
        <div class="fsci_r">
            <span class="sci_l">手机号</span>
            <input type="text" placeholder="请输入收货人手机号码" id="Mobile" name="Mobile" ng-model="Model.Mobile" class="sci_r">
        </div>
        <div class="f_bg_w">
            <section class="f_bd1 f_are">
                <a href="javascript:void(0)" ng-click="AreaShow()">
                    <dl>
                        <dt class="f_l f_fz14">所在地</dt>
                        <dd class="f_r f_rColor selectCity f_fz14" id="expressArea">
                        <span ng-show="!(Model.District>0)">请选择<img src="/Content/images/goto_c.png" class="f_ssqimg2"></span>
                            <label ng-show="Model.District>0">{{Model.ProvinceName}} {{Model.CityName}} {{Model.DistrictName}}</label>
                        </dd>
                    </dl>
                </a>
            </section>
            <textarea class="f_addDT" placeholder="请输入详细地址" id="Address" name="Address" ng-model="Model.Address"></textarea>
        </div>
    </div>
    <!--end 收货人信息 -->
    <!-- 是否设为默认地址 -->
    <div class="f_mt10 f_bg_w fscir2" ng-click="setIsDefault()">
        <label for="isdefultaddr" ng-class="{true:'fscir_is_default isdefault',false:'fscir_is_default'}[Model.IsDefault]">设为默认地址</label>
    </div>
    <!-- end 是否设为默认地址 -->
    <!-- 按钮 -->
    <button class="fscibtn" style="bottom:60px" ng-click="$state.go('user.address');">返回</button>
    <button class="fscibtn" ng-click="save()">保存</button>

    <!-- end 按钮 -->
    <!--地址选择-->
    <div class="w_addPopall">
        <div id="areaMask" class="mask" ng-show="showArea" ng-click="AreaHide()"></div>
        <div class="w_addPop" id="areaLayer"  ng-show="showArea">
            <div class="w_addPop_ti">收货地址<p class="w_popclose22" ng-click="AreaHide()"><img src="/Content/images/w2_22.png" class="w_addPopclose" /><img src="/Content/images/w2_23.png" class="w_addPopLine" /></p></div>
            <!--<ul class="w_addPop_menu" id="expressArea">
                <li>江苏</li>
                <li id="expres2">江苏</li>
                <li>江苏</li>
            </ul>-->
            <div class="f_poplist" id="areaBox">
                <ul class="f_popul" ng-show="level1">
                    <li ng-repeat="item in Province" ng-click="cp(item)">
                        {{item.Name}}
                    </li>

                </ul>
                <ul class="f_popul" ng-show="level2">
                    <li ng-repeat="item in City" ng-click="cc(item)">
                        {{item.Name}}
                    </li>
                </ul>
                <ul class="f_popul" ng-show="level3">
                    <li ng-repeat="item in District" ng-click="cd(item)">
                        {{item.Name}}
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <!--地址选择-->
</div>

<script>
        $(function() {
            //$('.f_popM').center();

            $(".closeBtn").click(function() {
                $("#areaMask").hide();
                $(".f_popM").hide();
            }
            );

            $(".btn").click(function() {
                $(this).animate( {
                    opacity: "0.6"
                }
                , 60);

                $(this).animate( {
                    opacity: "1"
                }
                , 100);
            }
            );
        });
        //// 默认地址的切换
        //var isdefault = 0;
        //$(".fscir_is_default").click(function(){
        //    if($(this).hasClass('isdefault') && isdefault == 0){
        //        isdefault = 1;
        //        $(this).removeClass('isdefault');
        //    }else{
        //        isdefault = 0;
        //        $(this).addClass('isdefault');
        //    }
        //})

        App.controller('AddressInfo', [
            '$scope', '$state', '$route', '$http', '$rootScope', '$stateParams',
                function ($scope, $state, $route, $http, $rootScope, $stateParams) {
                    $scope.level1 = true;
                    $scope.level2 = false;
                    $scope.level3 = false;
                    $scope.showArea = false;
                    if (!($stateParams.Id>0)) {
                        $scope.Model = {};
                        $scope.Model.IsDefault = true;
                    }
                    else {
                        $http.post("/UserCenter/GetAddressInfo", { id: $stateParams.Id }).then(function (response) {
                            $scope.Model = angular.copy(response.data.data);
                            if ($scope.Model == null) {
                                $scope.Model = {};
                            }

                        });
                    }

                    var tt = function () {
                        $rootScope.WxShare($rootScope.pageTitle(), '优品三悦', location.href, $rootScope.LogoUrl);
                    }

                    setTimeout(tt, 1000)
                    $http.post("/UserCenter/GetArea", { pid: 0 }).then(function (response) {
                        $scope.Province = angular.copy(response.data.data);
                        if ($scope.Province == null) {
                            $scope.Province = {};
                        }

                    });

                    $scope.AreaShow = function () {
                        $scope.level1 = true;
                        $scope.level2 = false;
                        $scope.level3 = false;
                        $scope.showArea = true;
                    }

                    $scope.AreaHide = function () {
                        $scope.showArea = false;
                    }

                    $scope.cp = function (item)
                    {
                        $scope.Model.ProvinceName = item.Name;
                        $scope.Model.Province = item.Id;
                        $scope.Model.City = 0;
                        $scope.Model.District = 0;
                        $http.post("/UserCenter/GetArea", { pid: item.Id }).then(function (response) {
                            $scope.City = angular.copy(response.data.data);
                            if ($scope.City == null) {
                                $scope.City = {};
                            }
                            $scope.level1 = false;
                            $scope.level2 = true;
                            $scope.level3 = false;
                        });
                    }

                    $scope.cc = function (item) {
                        $scope.Model.CityName = item.Name;
                        $scope.Model.City = item.Id;
                        $scope.Model.District = 0;
                        $http.post("/UserCenter/GetArea", { pid: item.Id }).then(function (response) {
                            $scope.District = angular.copy(response.data.data);
                            if ($scope.District == null) {
                                $scope.District = {};
                            }
                            $scope.level1 = false;
                            $scope.level2 = false;
                            $scope.level3 = true;
                        });
                    }

                    $scope.cd = function (item) {
                        $scope.Model.DistrictName = item.Name;
                        $scope.Model.District = item.Id;
                        $scope.showArea = false;
                    }

                    $scope.setIsDefault = function ()
                    {
                        if ($scope.Model.IsDefault) {
                            $scope.Model.IsDefault = false;
                            return;
                        }
                        else {
                            $scope.Model.IsDefault = true;
                            return;
                        }
                    }

                    $scope.save = function ()
                    {
                        
                        if ($scope.Model.Consignee == undefined || $scope.Model.Consignee=="")
                        {
                            layer.msg("请输入收货人姓名");
                            return false;
                        }
                        if ($scope.Model.Mobile == undefined || $scope.Model.Mobile == "") {
                            layer.msg("请输入收货人手机号");
                            return false;
                        }
                        if (!($scope.Model.District>0)) {
                            layer.msg("请选择所在地");
                            return false;
                        }
                        
                        if ($scope.Model.Address == undefined || $scope.Model.Address == "") {
                            layer.msg("请输入详细地址");
                            return false;
                        }
                        layer.load(2);
                        $http.post("/UserCenter/SaveAddress", { model: $scope.Model }).then(function (response) {
                            layer.closeAll('loading');
                            if (response.data.isSuccess) {
                                $state.go('user.address');
                            }
                            else {
                                layer.msg(response.data.msg);
                            }
                        });
                    }
                }
        ]);
</script>
